#ifndef ARA_EXEC_INTERNAL_EXECUTABLES_PARSER_H
#define ARA_EXEC_INTERNAL_EXECUTABLES_PARSER_H

#include "executable.h"
#include "manifest_parsing_error_domain.h"
#include "config/enter_exit_timeout.h"

namespace netaos{
namespace nosal {
namespace exec {
namespace internal {

class ExecutablesParser
{
public:
    /// @brief Constructor.
    /// @param root_path the root_path used to search for applications.
    /// @param ucmFilePath the path under which UCM-managed PROCESSES.json is located.
    /// @param default_process_timeout the default process timeout read from the Machine Manifest.
    ExecutablesParser(const std::string& root_path,
        const std::string& update_config_file_path,
        const config::EnterExitTimeout& default_process_timeout);

    /// @brief Deleted Copy Constructor.
    ExecutablesParser(const ExecutablesParser&) = delete;

    /// @brief Copy assignment operator deleted.
    ExecutablesParser& operator=(const ExecutablesParser&) = delete;

    /// @brief Move Constructor deleted.
    ExecutablesParser(ExecutablesParser&&) = default;

    /// @brief Move assignment operator deleted.
    ExecutablesParser& operator=(ExecutablesParser&&) = default;

    /// @brief Default destructor.
    ~ExecutablesParser() = default;

    /// @brief Triggers a parsing of all directories.
    /// @returns Result with list of all valid Executables found, error code otherwise.
    netaos::nosal::core::Result<std::vector<Executable>>&& ParseDirectories();

private:
    /// @brief Load the Executables.
    /// @returns Empty Result on success, error code otherwise.
    netaos::nosal::core::Result<void> LoadExecutables() noexcept;

    /// @brief Load the file paths to binaries and Execution Manifests.
    void LoadExecutablePaths() noexcept;

    /// @brief Read options from UCM's PROCESSES.json file
    void LoadUpdateConfigOptions();

    /// @brief Result returned by ParseDirectories.
    netaos::nosal::core::Result<std::vector<Executable>> list_of_executables_result_;

    /// @brief list of all Executables.
    std::vector<Executable> list_of_executables_;

    /// @brief list of all paths to binary and Execution Manifests.
    std::vector<std::tuple<std::string, std::string, std::string>> list_of_executable_paths_;

    /// @brief list of all directories where the parser found executables.
    std::vector<std::string> executable_directories_;

    /// @brief root_path under which applications shall be searched.
    std::string root_path_;

    /// @brief file path under which PROCESSES.json can be found for parsing.
    /// @note path is relative to root_path_.
    /// @note APD-specific implementation.
    std::string update_config_file_path_;

    /// @brief Default process timeout defined in the Machine Manifest.
    config::EnterExitTimeout default_process_timeout_;
};

}  // namespace internal
}  // namespace exec
}  // namespace nosal
}  // namespace netaos

#endif
